package com.javaGame.util;

import com.javaGame.frame.SortFrame;
import com.sun.source.doctree.SerialTree;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 排行榜信息处理类
 */
public class SortPress {
    public List<SortBean> read(){
        List<SortBean> list = new ArrayList<>();
        Reader r = null;
        BufferedReader br = null;

        try {
            //创建流
            r = new FileReader("doc/sort.txt");
            br = new BufferedReader(r);

            String str = "";
            //行读取，返回当前行所有的文本
            while( (str = br.readLine()) != null){
                //按空格拆分字符串
                String[] array = str.split("\\s+");
                //将数组元素封装为排行榜对象
                SortBean sortBean = new SortBean();
                sortBean.setPlayName(array[0]);
                sortBean.setPointer(Integer.parseInt(array[1]));
                //加入集合
                list.add(sortBean);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            //关闭流
            try {
                br.close();
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        return list;
    }

    public static void main(String[] args) {
        SortPress s = new SortPress();
        System.out.println(s.read());
    }
}
